package com.dirox.jira.notes.issuetab;

import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.plugin.issuetabpanel.AbstractIssueTabPanel;
import com.atlassian.jira.plugin.issuetabpanel.IssueTabPanel;
import com.atlassian.jira.security.JiraAuthenticationContext;
import com.atlassian.jira.security.PermissionManager;
import com.atlassian.jira.security.groups.GroupManager;
import com.atlassian.jira.user.util.UserUtil;
import com.dirox.jira.notes.service.NoteService;
import static com.google.common.base.Preconditions.checkNotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;


public class NoteTabPanel extends AbstractIssueTabPanel implements IssueTabPanel {
	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(
		NoteTabPanel.class);
	private final JiraAuthenticationContext context;
	private SearchService searchService;
	private NoteService noteService;
	private UserUtil userUtil;
	private GroupManager groupManager;
	private PermissionManager permissionManager;

	public NoteTabPanel(JiraAuthenticationContext context,
	                    SearchService searchService, NoteService noteService,
	                    UserUtil userUtil, GroupManager groupManager,
	                    PermissionManager permissionManager) {
		super();
		this.context = context;
		this.noteService = checkNotNull(noteService);
		this.searchService = checkNotNull(searchService);
		this.userUtil = checkNotNull(userUtil);
		this.groupManager = checkNotNull(groupManager);
		this.permissionManager = checkNotNull(permissionManager);
	}

	@SuppressWarnings({"unchecked", "rawtypes"})
	public List getActions(Issue issue, User remoteUser) {
		List<NoteIssueAction> panelActions = new ArrayList<NoteIssueAction>();
		NoteIssueAction action = new NoteIssueAction(
			descriptor,
			context,
			searchService,
			noteService,
			userUtil,
			groupManager,
			permissionManager);
		action.setIssue(issue);
		panelActions.add(action);

		return panelActions;
	}

	public boolean showPanel(Issue issue, User remoteUser) {
		return true;
	}
}
